Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
js canvas.toDataURL("image/png") return a error base64 code

My project requires me to get a screenshot from video by random frames.

 let oVideo = document.createElement("video");

  oVideo.setAttribute("src", this.localVideoURL);
  oVideo.setAttribute("controls", "controls");
  oVideo.currentTime = this.randomSecond; //Set the first second frame
  oVideo.load();
  oVideo.addEventListener("canplay", function (event) {
    let oCanvas = document.createElement("canvas");

    oCanvas.width = oVideo.videoWidth;
    oCanvas.height = oVideo.videoHeight;
    oCanvas.getContext("2d").drawImage(oVideo, 0, 0, oCanvas.width, oCanvas.height);

    let base64 = oCanvas.toDataURL("image/png");

    let frameCoverDom = document.getElementById("frameCoverDom");
    frameCoverDom.src = base64;
   
  });

This code works great on Windows and Android except iOS. Some of my friend's iPhone XR works perfectly too. Most iPhone that I tested got a blank image. After comparing my friend's phone and mine, I found that there was a difference on let base64 = oCanvas.toDataURL("image/png").

toDataURL returns:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAI4CAYAAAAbCTCbAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAABQKADAAQAAAABAAACOAAAAAAtaf5UAAAMfElEQVR4Ae3QMQEAAADCoPVPbQZ/iEBhwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwIABAwYMGDBgwI....  

This base64 code contains lots of "ABAwYMGDBgwI", and when I open it on the browser, it's a blank image with proper width and hieght.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda